import os
import sys

# 请在此输入您的代码

s = input()
k = int(input())
n = len(s)
maxl = -1
length = [0] * 26

left = 0
right = 0

while right < n:
    now = ord(s[right]) - ord('a')
    # print(now)
    length[now] += 1
    right += 1
    while left <= right and length[now] > k:
        length[ord(s[left]) - ord('a')] -= 1
        left += 1

    maxl = max(maxl, right - left)

print(maxl)
